<template>
  <div class="xtx-goods-page">
    <div class="container"
         v-if="goodData && goodData.brand">
      <!-- 商品信息 -->
      <div class="goods-info">
        <div class="media">
          <!-- 图片预览区 -->
          <XtxImageView :image-list="goodData.mainPictures" />
          <!-- 统计数量 -->
          <GoodSale :good="goodData" />
        </div>
        <div class="spec">
          <!-- 商品信息区 -->
          <GoodInfo :good="goodData" />
          <!-- sku组件 -->
          <XtxGoodSku :goods="goodData"
                      @change="skuChange" />
          <!-- 商品信息区 -->

          <!-- 数据组件 -->
          <XtxNumBox  :max="5" :min='1' v-model="num"></XtxNumBox>
          <!-- 按钮组件 -->
          <XtxButton type="primary"
                     style="margin-top: 20px">加入购物车</XtxButton>
        </div>
      </div>
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品详情 -->

        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside">

        </div>
      </div>
    </div>
  </div>
</template>

<script>
import GoodSale from './components/good-sale.vue'
import GoodInfo from './components/good-info.vue'
import { findGoods } from '@/api/detail'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
export default {
  components: {
    GoodSale,
    GoodInfo
  },
  setup () {
    const goodData = ref({})
    const route = useRoute()
    async function loadgoodData () {
      const res = await findGoods(route.params.id)
      goodData.value = res.result
    }
    loadgoodData()

    // sku组件
    function skuChange (sku) {
      console.log(sku)
    }

    // num
    const num = ref(2)
    setTimeout(() => {
      num.value = 4
    }, 3000)

    return {
      goodData,
      skuChange,
      num
    }
  }
}
</script>

<style scoped lang='less'>
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}

.number-box {
  display: flex;
  align-items: center;
  .label {
    width: 60px;
    color: #999;
    padding-left: 10px;
  }
}
</style>
